package nongchang.kuaijiecaifu.com.ncapp_android.ui;

import android.support.design.widget.TabLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import nongchang.kuaijiecaifu.com.ncapp_android.R;
import nongchang.kuaijiecaifu.com.ncapp_android.common.activity.BaseActivity;
import nongchang.kuaijiecaifu.com.ncapp_android.retrofit.good.Integral;
import nongchang.kuaijiecaifu.com.ncapp_android.ui.adapter.IntegralAdapter;
import nongchang.kuaijiecaifu.com.ncapp_android.ui.widget.LoadingLayout;
import nongchang.kuaijiecaifu.com.ncapp_android.ui.widget.OnLoadeMoreListener;

public class IntegralShopActivity extends BaseActivity {
    @BindView(R.id.orderby)
    TabLayout mTabOrderBy;
    @BindView(R.id.refresh)
    SwipeRefreshLayout mRefresh;
    @BindView(R.id.list)
    RecyclerView mListView;
    @BindView(R.id.loading)
    LoadingLayout mLoading;
    private IntegralAdapter integralAdapter;
    OnLoadeMoreListener mLoadMore = new OnLoadeMoreListener() {
        @Override
        public void onLoadMore(int page) {

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_integral_shop);
        setupToolbarWithHome(R.id.toolbar);
        ButterKnife.bind(this);
        mTabOrderBy.addTab(mTabOrderBy.newTab().setText("热门"), true);
        mTabOrderBy.addTab(mTabOrderBy.newTab().setText("推荐"));
        mTabOrderBy.addTab(mTabOrderBy.newTab().setText("全部"));
        mTabOrderBy.setOnTabSelectedListener(onTabSelectedListener);
        mListView.setLayoutManager(new LinearLayoutManager(this));
        integralAdapter = new IntegralAdapter(this);
        mListView.setAdapter(integralAdapter);
        mListView.addOnScrollListener(mLoadMore);
        mRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mRefresh.setRefreshing(true);
            }
        });
        load();
    }

    private void load() {
        List<Integral> list = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            Integral item = new Integral();
            item.yidui = 1;
            item.num = 32113;
            item.yuanjia = 666;
            item.jifen = 44;
            item.title = "我就是标题";
            item.image = "http://banbao.chazidian.com/uploadfile/2016-01-25/s145368924044608.jpg";
            list.add(item);
        }
        mLoading.showContent();
        integralAdapter.update(list);
    }

    TabLayout.OnTabSelectedListener onTabSelectedListener = new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {

        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {

        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {

        }
    };
}
